package mao.thinkinjava.concurency.deadlock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
  死锁的解决办法，就是让线程顺序获得锁，但是由于不同的哲学家需要的
  筷子不同，所以产生死锁。
 */
public class DeadLockDiningPhilosopher {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newCachedThreadPool();
        ChopStick[] sticks = new ChopStick[10];
        Philosopher.panderFact = 0.5;
        for (int i = 0; i < 10; i++) {
            sticks[i] = new ChopStick();
        }
        for (int i = 0; i < 10; i++) {
            executor.submit(new Philosopher(i,sticks[i],sticks[(i+1)%10]));
        }
        executor.shutdown();
    }
}
